/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.proyecto;

import com.proyecto.datos.EntityCarrera;
import com.proyecto.datos.EntityHorario;
import com.proyecto.datos.EntityHorarioLab;
import com.proyecto.datos.EntityHorarioMat;
import com.proyecto.datos.EntityMateria;
import com.proyecto.datos.EntityPlan;
import com.proyecto.modelado.Alumno;
import com.proyecto.modelado.Carrera;
import com.proyecto.modelado.Catedratico;
import com.proyecto.modelado.DetalleAlumno;
import com.proyecto.modelado.DetalleHorarioLab;
import com.proyecto.modelado.DetalleHorarioMateria;
import com.proyecto.modelado.Horario;
import com.proyecto.modelado.Materia;
import com.proyecto.modelado.Plan;
import java.util.ArrayList;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author mario
 */
public class frmAgregarAlumno extends javax.swing.JInternalFrame {

    Alumno al;
    Materia mat;
    Catedratico cat;
    Horario hor;
    Plan plan;
    DetalleHorarioLab detaHorLab;
    DetalleHorarioMateria detaMate;
    Carrera carre;
    ArrayList arry1;
    ArrayList arry2;
    ArrayList arry3;
    ArrayList arry4;
    EntityPlan entPlan;
    EntityMateria entMateria;
    EntityHorario entHora;
    EntityCarrera entCarre;
    EntityHorarioLab entLab;
    EntityHorarioMat entHorMat;
    int id_materia;
    int id_carrera;
    int id_plan;
    DetalleAlumno detal;

    public void Limpiarfrm() {
        this.jtxtCarnet.setText("");
        this.jtxtNombres.setText("");
        this.jtxtApellidos.setText("");
        this.jtxtGrupoClase.setText("");
        this.jtxtIdLaboratorio.setText("");

        this.jtxtGrupoClase.setEnabled(false);
        this.jtxtIdLaboratorio.setEnabled(false);


        //no funciona para limpiar los combo box
//        this.jrbtnPlan04.setSelected(false);
//        this.jrbtnPlan10.setSelected(false);
//        this.jcbCarrera.setSelectedItem("");
//        this.jcomboMateria.setSelectedItem("");


    }

    //TABLA PARA LOS HORARIOS DE LAS MATERIAS
    public void PopularTablaGrupoMateria(int id_materia) {

        //POPULANDO TABLE 10

        DefaultTableModel tabla1;
        Object[] fila = new Object[4];
        try {
            String[] columName = {"ID", "Materia", "Horario", "Grupo"};
            tabla1 = new DefaultTableModel(null, columName);
            //populamos el arraylist de la tabla
            ArrayList arry_10 = new ArrayList();
            detaMate = new DetalleHorarioMateria();
            EntityHorarioMat entDetaMate = new EntityHorarioMat();

            arry_10 = detaMate.MostrarCatalagoHorariosMateriaParam(id_materia);
            if (arry_10 != null) {
                for (int i = 0; i < arry_10.size(); i++) {
                    entDetaMate = (EntityHorarioMat) arry_10.get(i);
                    fila[0] = entDetaMate.getId_horario_materia();
                    fila[1] = entDetaMate.getEntMateria();
                    fila[2] = entDetaMate.getEntHorario();
                    fila[3] = entDetaMate.getGrupo();

                    tabla1.addRow(fila);
                }




                this.jtbleMateriaParam.setModel(tabla1);
            } else {
                JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la base de datos", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.toString());
        }
    }

    //TABLA PARA LAS BUSQUEDAS
    public void BusquedasTable(String datos) {



        DefaultTableModel tabla;
        Object[] fila = new Object[6];
        try {
            String[] columName = {"ID", "Materia", "Horario", "catedratico", "Grupo", "Cupo"};
            tabla = new DefaultTableModel(null, columName);
            // Recuperamos el ArrayList de la tabla y populamos el ArrayList del formulario
            ArrayList arry_busque = new ArrayList();
            detaHorLab = new DetalleHorarioLab();
            EntityHorarioLab entHoraLab = new EntityHorarioLab();
            arry_busque = detaHorLab.BuscarHorario(datos);

            if (arry_busque != null) {
                for (int i = 0; i < arry_busque.size(); i++) {
                    entHoraLab = (EntityHorarioLab) arry_busque.get(i);
                    fila[0] = entHoraLab.getId();
                    fila[1] = entHoraLab.getEntMateria();
                    fila[2] = entHoraLab.getEntHorario();
                    fila[3] = entHoraLab.getEntCatedratico();
                    fila[4] = entHoraLab.getEntGrupo();
                    fila[5] = entHoraLab.getCupo();

                    tabla.addRow(fila);
                }

                this.jtbleHorarios.setModel(tabla);
            } else {
                JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la base de datos", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.toString());
        }
    }

    public void PopularTableLab(int id_materia) {

        //POPULANDO TABLE 10

        DefaultTableModel tabla;
        Object[] fila = new Object[6];
        try {
            String[] columName = {"ID", "Materia", "Horario", "catedratico", "Grupo"};
            tabla = new DefaultTableModel(null, columName);
            //populamos el arraylist de la tabla
            ArrayList arry_5 = new ArrayList();
            detaHorLab = new DetalleHorarioLab();
            EntityHorarioLab entHoraLab = new EntityHorarioLab();

            arry_5 = detaHorLab.MostrarHorariosPlan10(id_materia);
            if (arry_5 != null) {
                for (int i = 0; i < arry_5.size(); i++) {
                    entHoraLab = (EntityHorarioLab) arry_5.get(i);
                    fila[0] = entHoraLab.getId();
                    fila[1] = entHoraLab.getEntMateria();
                    fila[2] = entHoraLab.getEntHorario();
                    fila[3] = entHoraLab.getEntCatedratico().concat(" ").concat(entHoraLab.getEntCatedraticoApellido());
                    fila[4] = entHoraLab.getEntGrupo();
//                  fila[5] = entHoraLab.getCupo();

                    tabla.addRow(fila);
                }




                this.jtbleHorarios.setModel(tabla);
            } else {
                JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la base de datos", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.toString());
        }
    }

    //Cargando combo box 2010
//    public void CargarComboBox10() {
//
//        ArrayList arryRad = new ArrayList();
//        arryRad = mat.MostrarMateriasPlan10();
//        JList list_rad = new JList();
//        DefaultListModel listModel_rad = new DefaultListModel();
//        listModel_rad.addElement("Seleccione");
//        if (arryRad != null) {
//            for (int i = 0; i < arryRad.size(); i++) {
//                entMateria = (EntityMateria) arryRad.get(i);
//                listModel_rad.addElement(entMateria.getCodigo_asignatura());
//            }
//        } else {
//            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
//        }
//        list_rad.setModel(listModel_rad);
//        this.jcomboMateria.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
//        this.jcomboMateria.setSelectedIndex(0);
//
//    }

//    public void PopularTable04(int id_materia) {
//        //POPULANDO TABLE
//
//        DefaultTableModel tabla;
//        Object[] fila = new Object[6];
//        try {
//            String[] columName = {"ID", "Materia", "Horario", "catedratico", "Grupo", "Cupo"};
//            tabla = new DefaultTableModel(null, columName);
//            //populamos el arraylist de la tabla
//            ArrayList arry_4 = new ArrayList();
//            detaHorLab = new DetalleHorarioLab();
//            EntityHorarioLab entHoraLab = new EntityHorarioLab();
//
//            arry_4 = detaHorLab.MostrarHorariosPlan04(id_materia);
//            if (arry_4 != null) {
//                for (int i = 0; i < arry_4.size(); i++) {
//                    entHoraLab = (EntityHorarioLab) arry_4.get(i);
//                    fila[0] = entHoraLab.getId();
//                    fila[1] = entHoraLab.getEntMateria();
//                    fila[2] = entHoraLab.getEntHorario();
//                    fila[3] = entHoraLab.getEntCatedratico();
//                    fila[4] = entHoraLab.getEntGrupo();
//                    fila[5] = entHoraLab.getCupo();
//
//                    tabla.addRow(fila);
//                }
//                this.jtbleHorarios.setModel(tabla);
//            } else {
//                JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la base de datos", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
//            }
//        } catch (Exception ex) {
//            JOptionPane.showMessageDialog(rootPane, ex.toString());
//        }
//    }

    //CargarCombo box 04
//    public void CargarComboBox04() {
//        //CARGANDO COMBOBOX DE MATERIAS
//        ArrayList arryRad = new ArrayList();
//        arryRad = mat.MostrarMateriasPlan04();
//        JList list_rad = new JList();
//        DefaultListModel listModel_rad = new DefaultListModel();
//        listModel_rad.addElement("Seleccione");
//        if (arryRad != null) {
//            for (int i = 0; i < arryRad.size(); i++) {
//                entMateria = (EntityMateria) arryRad.get(i);
//                listModel_rad.addElement(entMateria.getCodigo_asignatura());
//            }
//        } else {
//            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
//        }
//        list_rad.setModel(listModel_rad);
//        this.jcomboMateria.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
//        this.jcomboMateria.setSelectedIndex(0);
//    }

    //bloqueando controles
    public void BloquearControles() {
        this.jtxtIdLaboratorio.setEnabled(false);
        this.jtxtGrupoClase.setEnabled(false);
    }
    
    public void cargarComboboxPlan() {
        
        ArrayList arryPlan = new ArrayList();
        plan = new Plan();
        arryPlan = plan.MostrarPlan();
        JList list_rad = new JList();
        DefaultListModel listModel_rad = new DefaultListModel();
        
        listModel_rad.addElement("Seleccione");
        if (arryPlan != null) {
            for (int i = 0; i < arryPlan.size(); i++) {
                entPlan = (EntityPlan) arryPlan.get(i);
                listModel_rad.addElement(entPlan.getNombre_plan());
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
        }
        list_rad.setModel(listModel_rad);

        //seteando dos combos con los planes

        this.jcmbPlan.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
        this.jcmbPlan.setSelectedIndex(0);
      
    }
    
      public void CargarComboBoxMateria(int id_plan) {
        //CARGANDO COMBOBOX DE MATERIAS
        ArrayList arryRad = new ArrayList();
        arryRad = mat.MostrarMateriasPlan_I_Alumno(id_plan);
        JList list_rad = new JList();
        DefaultListModel listModel_rad = new DefaultListModel();
        listModel_rad.addElement("Seleccione");
        if (arryRad != null) {
            for (int i = 0; i < arryRad.size(); i++) {
                entMateria = (EntityMateria) arryRad.get(i);
                listModel_rad.addElement(entMateria.getCodigo_asignatura());
            }
        } else {
            JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Materia", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
        }
        list_rad.setModel(listModel_rad);
        this.jcomboMateria.setModel(new DefaultComboBoxModel(listModel_rad.toArray()));
        this.jcomboMateria.setSelectedIndex(0);
    }

    /**
     * Creates new form frmAgregarAlumno
     */
    public frmAgregarAlumno() {
        initComponents();
        this.setTitle("Agrear nuevo alumno");

        al = new Alumno();
        mat = new Materia();
        cat = new Catedratico();
        hor = new Horario();
        plan = new Plan();
        carre = new Carrera();
        entMateria = null;
        entHora = null;
        entPlan = null;
        entCarre = null;
        entLab = null;
        entHorMat = null;

        BloquearControles();
        cargarComboboxPlan();


        try {

            //CARRERA
            arry4 = new ArrayList();
            arry4 = carre.MostrarCarrera();
            JList list_4 = new JList();
            DefaultListModel listModel_4 = new DefaultListModel();

            listModel_4.addElement(
                    "Seleccione");
            if (arry4
                    != null) {
                for (int i = 0; i < arry4.size(); i++) {
                    entCarre = (EntityCarrera) arry4.get(i);
                    listModel_4.addElement(entCarre.getNombre_carrera());
                }
            } else {
                JOptionPane.showMessageDialog(rootPane, "No se recuperaron datos de la tabla Carrera", "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);
            }

            list_4.setModel(listModel_4);

            this.jcbCarrera.setModel(
                    new DefaultComboBoxModel(listModel_4.toArray()));
            this.jcbCarrera.setSelectedIndex(
                    0);


        } catch (Exception ex) {
            JOptionPane.showMessageDialog(rootPane, ex.toString());
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jbtnCerrar = new javax.swing.JButton();
        jlblCarnet = new javax.swing.JLabel();
        jlblNombres = new javax.swing.JLabel();
        jlblApellidos = new javax.swing.JLabel();
        jlblMateria = new javax.swing.JLabel();
        jlblHorario = new javax.swing.JLabel();
        jbtnAgregar = new javax.swing.JButton();
        jtxtCarnet = new javax.swing.JTextField();
        jtxtNombres = new javax.swing.JTextField();
        jtxtApellidos = new javax.swing.JTextField();
        jcomboMateria = new javax.swing.JComboBox();
        jlblCarrera = new javax.swing.JLabel();
        jcbCarrera = new javax.swing.JComboBox();
        jlblGrupoClase = new javax.swing.JLabel();
        jtxtGrupoClase = new javax.swing.JTextField();
        jlblPlan = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtbleHorarios = new javax.swing.JTable();
        jbtnMostrar = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbleMateriaParam = new javax.swing.JTable();
        jLabel1 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        jtxtIdLaboratorio = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jcmbPlan = new javax.swing.JComboBox();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setPreferredSize(new java.awt.Dimension(575, 800));

        jbtnCerrar.setBackground(new java.awt.Color(202, 102, 102));
        jbtnCerrar.setText("Cancelar");
        jbtnCerrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbtnCerrarMouseClicked(evt);
            }
        });

        jlblCarnet.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jlblCarnet.setText("Carnet:");

        jlblNombres.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jlblNombres.setText("Nombres:");

        jlblApellidos.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jlblApellidos.setText("Apellidos:");

        jlblMateria.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jlblMateria.setText("Materia:");

        jlblHorario.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jlblHorario.setText("Horarios de Laboratorios");

        jbtnAgregar.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jbtnAgregar.setForeground(new java.awt.Color(44, 166, 93));
        jbtnAgregar.setIcon(new javax.swing.ImageIcon("/home/mario/Dropbox/Sistema de laboratorio/Imagenes/agregar.jpg")); // NOI18N
        jbtnAgregar.setText("Agregar");
        jbtnAgregar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbtnAgregarMouseClicked(evt);
            }
        });

        jtxtApellidos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtApellidosActionPerformed(evt);
            }
        });

        jcomboMateria.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcomboMateriaItemStateChanged(evt);
            }
        });
        jcomboMateria.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jcomboMateriaActionPerformed(evt);
            }
        });

        jlblCarrera.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jlblCarrera.setText("Carrera:");

        jcbCarrera.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcbCarreraItemStateChanged(evt);
            }
        });

        jlblGrupoClase.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jlblGrupoClase.setText("ID Grupo de clase:");

        jlblPlan.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jlblPlan.setText("Plan de estudio:");

        jtbleHorarios.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jtbleHorarios.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jScrollPane2.setViewportView(jtbleHorarios);

        jbtnMostrar.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jbtnMostrar.setIcon(new javax.swing.ImageIcon("/home/mario/Dropbox/Sistema de laboratorio/Imagenes/mostrar.png")); // NOI18N
        jbtnMostrar.setText("Mostrar");
        jbtnMostrar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jbtnMostrarMouseClicked(evt);
            }
        });
        jbtnMostrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnMostrarActionPerformed(evt);
            }
        });

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jtbleMateriaParam.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jtbleMateriaParam.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jScrollPane1.setViewportView(jtbleMateriaParam);

        jLabel1.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel1.setText("Grupos de Clase");

        jLabel2.setFont(new java.awt.Font("Ubuntu", 1, 15)); // NOI18N
        jLabel2.setText("ID Grupo Lab:");

        jLabel3.setFont(new java.awt.Font("Ubuntu", 0, 12)); // NOI18N
        jLabel3.setForeground(new java.awt.Color(225, 22, 22));
        jLabel3.setText("Máx. 8 caracteres");

        jcmbPlan.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jcmbPlan.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jcmbPlanItemStateChanged(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(35, 35, 35)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jlblCarrera)
                                        .addGap(91, 91, 91)
                                        .addComponent(jcbCarrera, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                            .addComponent(jlblApellidos)
                                            .addGap(78, 78, 78)
                                            .addComponent(jtxtApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(layout.createSequentialGroup()
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addComponent(jlblNombres)
                                                .addComponent(jlblCarnet))
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                .addGroup(layout.createSequentialGroup()
                                                    .addComponent(jtxtCarnet, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                    .addComponent(jLabel3))
                                                .addComponent(jtxtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                .addContainerGap(35, Short.MAX_VALUE)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlblMateria)
                                            .addComponent(jlblPlan))
                                        .addGap(33, 33, 33)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jcomboMateria, javax.swing.GroupLayout.PREFERRED_SIZE, 265, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jcmbPlan, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                    .addGroup(layout.createSequentialGroup()
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jlblGrupoClase)
                                            .addComponent(jLabel2))
                                        .addGap(19, 19, 19)
                                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jtxtGrupoClase)
                                            .addComponent(jtxtIdLaboratorio, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(26, 26, 26)))
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 476, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(224, 224, 224)
                        .addComponent(jlblHorario))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 607, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 607, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addComponent(jbtnMostrar, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(26, 26, 26)
                                .addComponent(jbtnAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jbtnCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(246, 246, 246)
                        .addComponent(jLabel1)))
                .addContainerGap(17, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jLabel1)
                        .addGap(31, 31, 31)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(30, 30, 30)
                        .addComponent(jlblHorario)
                        .addGap(27, 27, 27)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 230, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jbtnAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbtnCerrar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jbtnMostrar, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlblCarnet)
                            .addComponent(jtxtCarnet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(48, 48, 48)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlblNombres)
                            .addComponent(jtxtNombres, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(42, 42, 42)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlblApellidos)
                            .addComponent(jtxtApellidos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jcbCarrera, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlblCarrera))
                        .addGap(34, 34, 34)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(68, 68, 68)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlblPlan)
                            .addComponent(jcmbPlan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jlblMateria)
                            .addComponent(jcomboMateria, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(35, 35, 35)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jtxtGrupoClase, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jlblGrupoClase))
                        .addGap(33, 33, 33)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(jtxtIdLaboratorio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(0, 2, Short.MAX_VALUE)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 648, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        setBounds(0, 0, 1134, 679);
    }// </editor-fold>//GEN-END:initComponents

    private void jtxtApellidosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtApellidosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtApellidosActionPerformed

    private void jbtnCerrarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbtnCerrarMouseClicked
        // TODO add your handling code here:
        entCarre = null;
        entHorMat = null;
        entHora = null;
        entLab = null;
        entMateria = null;
        entPlan = null;
        arry1 = null;
        arry2 = null;
        arry3 = null;
        arry4 = null;


        this.dispose();
    }//GEN-LAST:event_jbtnCerrarMouseClicked

    private void jbtnAgregarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbtnAgregarMouseClicked
        // TODO add your handling code here:


        int fila = this.jtbleHorarios.getSelectedRow();
        int fila1 = this.jtbleMateriaParam.getSelectedRow();

        try {

            String carnet = this.jtxtCarnet.getText();
            String nombre = this.jtxtNombres.getText();
            String apellido = this.jtxtApellidos.getText();
            int id_carrera1 = this.id_carrera;

            //Asignando texto a controles para la insercion
            this.jtxtIdLaboratorio.setText(String.valueOf(this.jtbleHorarios.getValueAt(fila, 0)));
            int id_lab = Integer.parseInt(this.jtxtIdLaboratorio.getText());
            this.jtxtGrupoClase.setText(String.valueOf(this.jtbleMateriaParam.getValueAt(fila1, 0)));
            int id_grupo = Integer.parseInt(this.jtxtGrupoClase.getText());

            
                detal = new DetalleAlumno();
                String msj = detal.InsertarAlumnoYDetalle(carnet, nombre, apellido, id_carrera1, id_lab, id_grupo);
                JOptionPane.showMessageDialog(rootPane, msj, "CONFIRMACIÓN", JOptionPane.INFORMATION_MESSAGE);

                Limpiarfrm();
            
              

        } catch (Exception ex) {
            System.out.println(ex.toString());
        }


    }//GEN-LAST:event_jbtnAgregarMouseClicked

    private void jcomboMateriaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcomboMateriaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jcomboMateriaActionPerformed

    private void jcomboMateriaItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcomboMateriaItemStateChanged
        // TODO add your handling code here:

        //Obteniendo id del combo

        ArrayList arryRad = new ArrayList();
        arryRad = mat.MostrarMaterias();
        for (int i = 0; i < arryRad.size(); i++) {
            entMateria = (EntityMateria) arryRad.get(i);
            if (this.jcomboMateria.getSelectedItem().equals(entMateria.getCodigo_asignatura())) {
                id_materia = entMateria.getId_materia();
            }
        }

        PopularTablaGrupoMateria(id_materia);

    }//GEN-LAST:event_jcomboMateriaItemStateChanged

    private void jbtnMostrarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jbtnMostrarMouseClicked
        // TODO add your handling code here:
        PopularTableLab(id_materia);
    }//GEN-LAST:event_jbtnMostrarMouseClicked

    private void jcbCarreraItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcbCarreraItemStateChanged
        // TODO add your handling code here:
        for (int i = 0; i < arry4.size(); i++) {
            entCarre = (EntityCarrera) arry4.get(i);
            if (this.jcbCarrera.getSelectedItem().equals(entCarre.getNombre_carrera())) {
                this.id_carrera = entCarre.getId_carrera();
            }
        }
    }//GEN-LAST:event_jcbCarreraItemStateChanged

    private void jbtnMostrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnMostrarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jbtnMostrarActionPerformed

    private void jcmbPlanItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jcmbPlanItemStateChanged
        
        ArrayList arryPlan = new ArrayList();
        
        plan = new Plan();
        arryPlan=plan.MostrarPlan();
        
        for (int i = 0; i < arryPlan.size(); i++) {
            entPlan = (EntityPlan) arryPlan.get(i);
            if (this.jcmbPlan.getSelectedItem().equals(entPlan.getNombre_plan())) {
                this.id_plan = entPlan.getId_plan();
            }
        }
         
         CargarComboBoxMateria(id_plan);
    }//GEN-LAST:event_jcmbPlanItemStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JButton jbtnAgregar;
    private javax.swing.JButton jbtnCerrar;
    private javax.swing.JButton jbtnMostrar;
    private javax.swing.JComboBox jcbCarrera;
    private javax.swing.JComboBox jcmbPlan;
    private javax.swing.JComboBox jcomboMateria;
    private javax.swing.JLabel jlblApellidos;
    private javax.swing.JLabel jlblCarnet;
    private javax.swing.JLabel jlblCarrera;
    private javax.swing.JLabel jlblGrupoClase;
    private javax.swing.JLabel jlblHorario;
    private javax.swing.JLabel jlblMateria;
    private javax.swing.JLabel jlblNombres;
    private javax.swing.JLabel jlblPlan;
    private javax.swing.JTable jtbleHorarios;
    private javax.swing.JTable jtbleMateriaParam;
    private javax.swing.JTextField jtxtApellidos;
    private javax.swing.JTextField jtxtCarnet;
    private javax.swing.JTextField jtxtGrupoClase;
    private javax.swing.JTextField jtxtIdLaboratorio;
    private javax.swing.JTextField jtxtNombres;
    // End of variables declaration//GEN-END:variables
}
